package com.tomecode.tools.maven.settings.model;

/**
 * Download policy
 * 
 * @author Tomas Frastia
 * 
 * @see http://www.tomecode.com or
 *      http://code.google.com/p/maven-settings-editor/
 * 
 */
public final class Release
{
  /**
   * Whether to use this repository for downloading this type of artifact.
   */
  private boolean enabled = true;
  /**
   * The frequency for downloading updates - can be "always", "daily" (default),
   * "interval:XXX" (in minutes) or "never" (only if it doesn't exist locally).
   */
  private UpdatePolicy updatePolicy;
  /**
	 * 
	 */
  private int updatePolicyInterval = 0;
  /**
   * What to do when verification of an artifact checksum fails - warn, fail,
   * etc. Valid values are "fail" or "warn".
   */
  private ChecksumPolicy checksumPolicy;

  public Release()
  {

  }

  /**
   * Copy exits {@link Release} to new {@link Release}
   * 
   * @param releases
   */
  public Release(Release releases)
  {
    checksumPolicy = releases.getChecksumPolicy();
    enabled = releases.isEnabled();
    updatePolicy = releases.getUpdatePolicy();
    updatePolicyInterval = releases.getUpdatePolicyInterval();
  }

  public final UpdatePolicy getUpdatePolicy()
  {
    return updatePolicy;
  }

  public final void setUpdatePolicy(String updatePolicy)
  {
    this.updatePolicy = UpdatePolicy.parse(updatePolicy);
    if (this.updatePolicy == UpdatePolicy.INTERVAL) {
      updatePolicyInterval = UpdatePolicy.parseInterval(updatePolicy);
    }
  }

  public final ChecksumPolicy getChecksumPolicy()
  {
    return checksumPolicy;
  }

  public final void setChecksumPolicy(String checksumPolicy)
  {
    this.checksumPolicy = ChecksumPolicy.parse(checksumPolicy);
  }

  public final void setEnabled(boolean enabled)
  {
    this.enabled = enabled;
  }

  public final boolean isEnabled()
  {
    return enabled;
  }

  public final int getUpdatePolicyInterval()
  {
    return updatePolicyInterval;
  }

  public final String makeUpdatePolicy()
  {
    if (updatePolicy == UpdatePolicy.INTERVAL) {
      return UpdatePolicy.getInterval(updatePolicyInterval);
    } else if (updatePolicy == null) {
      return "";
    }
    return updatePolicy.toString();
  }

}
